/**
    Copyright (c) 2010 yakiimo02
    Distributed under the New BSD License.
    See included license.txt or http://www.yakiimo3d.com/NewBSDLicense.txt
**/

#pragma once

#include "reference/SmallPtDefines.h"

#include <math.h>
#include <stdlib.h>
#include <stdio.h>  

namespace REF
{

#define M_PI_REF       3.14159265358979323846

/**    
    @return [0,1]
*/
inline SPT_FLOAT drand48()
{
    return (SPT_FLOAT)rand()/(SPT_FLOAT)RAND_MAX;
}

/**
*/
struct Vec 
{
public:
    SPT_FLOAT x, y, z;                  // position, also color (r,g,b)
public:
    Vec(SPT_FLOAT x_=0, SPT_FLOAT y_=0, SPT_FLOAT z_=0){ x=x_; y=y_; z=z_; }
    Vec operator+(const Vec &b) const { return Vec(x+b.x,y+b.y,z+b.z); }
    Vec operator-(const Vec &b) const { return Vec(x-b.x,y-b.y,z-b.z); }
    Vec operator*(SPT_FLOAT b) const { return Vec(x*b,y*b,z*b); }
    Vec mult(const Vec &b) const { return Vec(x*b.x,y*b.y,z*b.z); }
    Vec& norm(){ return *this = *this * (1/sqrt(x*x+y*y+z*z)); }
    SPT_FLOAT dot(const Vec &b) const { return x*b.x+y*b.y+z*b.z; } // cross:
    Vec operator%(Vec&b){return Vec(y*b.z-z*b.y,z*b.x-x*b.z,x*b.y-y*b.x);}
};

}